package com.demo.component

import android.view.View
import com.base.tool.log.LogPrint
import com.demo.Tags


/**
这个线程一旦执行run方法，马上就把自己挂起来了，等待notify()或者notifyAll()，然而没有其它线程来唤醒它，因此它会一直活着，所持有的资源也不会释放
**/
class LeakingThread1 : Thread() {
  val TAG = Tags.LeakingThread

  val leakedViews = mutableListOf<View>()

  init {
    name = "Leaking thread"
    start()
    LogPrint.d(TAG, "Start Thread")
  }

  override fun run() {
    LogPrint.d(TAG, "List:$leakedViews")

    synchronized(obj) {
      LogPrint.d(TAG, "I get the lock, and do something")
      obj.wait()//挂起线程，直到线程得到notify()或者notifyAll()消息

      LogPrint.d(TAG, "continue")

    }

    LogPrint.d(TAG, "I'm finish!")

  }

  companion object {
    private val obj = Object()
    val thread = LeakingThread1()
  }
}